package com.zeta.eduservice.service.impl;

import com.zeta.eduservice.entity.question.EduFolder;
import com.zeta.eduservice.entity.vo.front.folderListVo;
import com.zeta.eduservice.mapper.EduFolderMapper;
import com.zeta.eduservice.service.EduFolderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.apache.catalina.mapper.Mapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文件夹 服务实现类
 * </p>
 *
 * @author zeta
 * @since 2020-08-24
 */
@Service
public class EduFolderServiceImpl extends ServiceImpl<EduFolderMapper, EduFolder> implements EduFolderService {

	
	@Override
	public List<folderListVo> getAll(String teacherId) {
		QueryWrapper<EduFolder> queryWrapper=new QueryWrapper<EduFolder>();
		queryWrapper.eq("teacherId",teacherId );
		List<EduFolder> selectList = baseMapper.selectList(queryWrapper);
		
		ArrayList<folderListVo> parentList = new ArrayList<folderListVo>();
		
	for(EduFolder i:selectList) {
		if(i.getParentId().equals("0")) {
			folderListVo folderListVo = new folderListVo();
			BeanUtils.copyProperties(i, folderListVo);
			parentList.add(folderListVo);
			selectList.remove(i);
		}
	}
	for(folderListVo i:parentList) {
		ArrayList<folderListVo> childrenList = new ArrayList<folderListVo>();
		for(EduFolder j:selectList) {
			if(j.getParentId().equals(i.getId())) {
				folderListVo folderListVo = new folderListVo();
				BeanUtils.copyProperties(j, folderListVo);
				childrenList.add(folderListVo);
				selectList.remove(j);
				
			}
		}
		i.setChildren(childrenList);
	}
		return parentList;
	}

}
